<?php 

class URL {

	public $siteUrl;
	public $fullUrl;
	public $queryUrl;

	public function __construct(){
		global $siteUrl, $queryUrl, $controller, $method, $default_controller, $default_method;
		
		$c = $controller;
		if($controller == $default_controller) $c = '';
		
		$m = $method;
		if($method == $default_method) $m = '';
		
		$queryUrl = trim($queryUrl,'/');
		
		$this->siteUrl = 
			$this->add_http(
				trim($siteUrl,'/')
			) . '/';
			
		$this->fullUrl = 
			$this->add_http(
				trim($this->siteUrl . $queryUrl,'/')
			) . '/';
		
		$this->actionUrl = 
			$this->add_http(
				trim($siteUrl.'/'.$c.'/'.$m, '/')
			)  . '/';
			
		$this->queryUrl = explode('/', $queryUrl);
	}

	public function query($index = null){
		return (isset($this->queryUrl[$index])) ? $this->queryUrl[$index] : $this->queryUrl ;
	}
	
	public function link($string, $current = true){
		$link = ($current === true) ? $this->fullUrl .'/'.$string : $this->siteUrl .'/'.$string ;
		return $this->add_http($link);
	}
	
	public function add_http($url, $secure = false){
		
		$http = 'http://';
		if($secure === true){
			$http = 'https://';
		}
		
		if(strstr($url,$http) == ''){
			$url = $http . $url;
		}
		
		return $url;
	}
	
	public function assets($file){
		global $assetsDir;
		
		return $this->link($assetsDir.'/css'.$file,false);
	}
	
	public function css($file){
		return $this->assets('/css'.$file.'.css');
	}
	
	public function js($file){
		return $this->assets('/js'.$file.'.js');
	}
	
}

?>